<template>
	<view class="carList">
		<block v-for="(item,index) in list">
			<view class="list flex-between" v-if="item.model" @click="setDefault(item.id,index)">
				<view>
					<view class="name flex">
						{{item.model}}
						
						<view v-if="item.is_default">默认</view>
					</view>
					<view class="num flex">
						<text>{{item.plate_number}}</text>
						<view>已认证</view>
					</view>
				</view>
				<image src="/static/arrow.png" mode="widthFix"></image>
			</view>
		</block>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[]
			};
		},
		onLoad() {
			
		},
		onShow(){
			this.getList();
		},
		methods:{
			setDefault(id,index){
				uni.showModal({
					content:'是否设为默认车辆？',
					success:r=>{
						if(r.confirm){
							this.$https.post('car_auth/setDefault',{
								id:id
							}).then(res=>{
								uni.showToast({
									title:'设置成功',
									icon:'none'
								})
								let list = this.list;
								for(let i = 0 ;i<list.length;i++){
									list[i].is_default = 0
								}
								list[index].is_default = 1;
								this.list = list;
							})
						}
					}
				})
				
			},
			getList(){
				this.$https.get('car_auth').then(res=>{
					console.log(res)
					this.list = res.list;
				})
			}
		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url:"/pages/self/addCar"
			})
		}
	}
</script>

<style lang="less">
	page{
		background: #f2f3f4;
	}
	@color: #4CD964;
	.carList{
		margin: 30rpx 0;
		.list{
			padding: 24rpx 30rpx;
			margin-bottom: 6rpx;
			background: white;
			.name{
				font-size: 32rpx ;
				font-weight: bold;
				margin-bottom: 15rpx;
				view{
					background: #007AFF;
					color:white;
					font-size: 24rpx;
					font-weight: normal;
					padding: 0 15rpx;
					border-radius: 6rpx;
					margin-left: 15rpx;
				}
			}
			.num{
				font-size: 26rpx;
				color:#666;
				view{
					font-size: 24rpx;
					background:@color ;
					color:white;
					padding: 0 10rpx;
					margin-left: 20rpx;
					border-radius: 10rpx;
				}
			}
			image{
				width: 30rpx;
				height: auto;
			}
		}
	}
</style>
